package com.question.dicegame;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class DiceGameFrame extends JFrame{

	private MainScreen screen;
	private DiceGameBoard screen2;
	private JPanel mainPanel;
	private JButton button1, button2, button3;
	public JButton button;
	public DiceGameFrame() {
		init();
	}

	private void init() {

		setSize(new Dimension(Constants.FRAME_WIDTH,
				Constants.FRAME_HEIGHT));
		setResizable(false);
		setTitle("Dice Game");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		panelProcess();
	}

	public void panelProcess() {
		
		screen = new MainScreen();
		screen.setFocusable(true);
		screen.setPreferredSize(new Dimension(Constants.MAINBG_WIDTH,
				Constants.MAINBG_HEIGHT));

		
		
		button1 = new JButton();
		//button2 = new JButton();
		button3 = new JButton();
		button1.setText("START");
		button3.setText("EXIT");
		button1.setSize(150, 50);
		button3.setSize(150, 50);
		button1.setLocation((int) ((getWidth() - button1.getWidth()) / 2),
				(int) ((getHeight() - button1.getHeight()) / 1.15));
		button3.setLocation((int) ((getWidth() - button1.getWidth()) / 1.2),
				(int) ((getHeight() - button1.getHeight()) / 1.15));
		
		button1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
			System.out.println("됬냐");
			

			
			screen2 = new DiceGameBoard();
			screen2.setFocusable(true);
			screen2.setPreferredSize(new Dimension(Constants.FRAME_WIDTH,
						Constants.FRAME_HEIGHT));
			
			//버튼
			button = new JButton();
			button.setText("Roll");
			button.setSize(140, 60);
			button.setLocation(810,720);
			button.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					screen2.number = (int) ((Math.random() * 6) + 1);
					System.out.println(screen2.number);
				}
			});
			
			add(button,BorderLayout.EAST);
			add(screen2,BorderLayout.CENTER);
			pack();
			remove(button3);
			remove(button1);
			remove(screen);	
			validate();
			}
		});
		button3.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
			
				System.exit(0);
			}
		});
		
		add(button1);
		add(button3);
		add(screen);
		pack();
	}
	
}

